// -------------------------------------------------------------------------
//    @FileName         :    NFIAccountRedisModule.h
//    @Author           :    LvSheng.Huang
//    @Date             :    2016-11-07
//    @Module           :    NFIAccountRedisModule
//
// -------------------------------------------------------------------------

#ifndef NFI_ACCOUNT_REDIS_MODULE_H
#define NFI_ACCOUNT_REDIS_MODULE_H

#include "NFIModule.h"
#include "NFComm/NFPluginModule/NFIAsyMysqlModule.h"

class NFIAccountDBModule
    : public NFIModule
{

public:
    virtual int VerifyAccount(const std::string& strAccount, const std::string& strPwd) = 0;
    virtual bool AddAccount(const std::string& strAccount, const std::string& strPwd) = 0;
    virtual bool ExistAccount(const std::string& strAccount) = 0;

    template<typename BaseType>
    int SendAsynGetAccountInfoFromMysql(const NFGUID& client, const std::string& account, int gateId,
                                        BaseType* pBaseType, void (BaseType::*handleReturnRsp)(const NFGUID&, const int, const std::vector<std::string>&, const std::vector<std::string>&, const std::string&))
    {
        const MYSQL_RETURN_VECKEY_VECVALUE_FUNCTOR mFunReturnVeckKeyValueRsp = std::bind(handleReturnRsp, pBaseType, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5);

        return SendAsynGetAccountInfoFromMysql(client, account, gateId, mFunReturnVeckKeyValueRsp);
    }

    virtual int SendAsynGetAccountInfoFromMysql(const NFGUID& client, const std::string& account, int gateId, const MYSQL_RETURN_VECKEY_VECVALUE_FUNCTOR& mFunReturnVeckKeyValueRsp) = 0;

    virtual bool CreateAccountInfoToMysql(const std::string& strAccount, const NFGUID& id) = 0;
    virtual void RecvCreateAccountInfoToMysql(const NFGUID& self, const int nRet, const std::string& strUseData) = 0;

    virtual bool ExistRoleGuid(const NFGUID& id) = 0;
    virtual bool CreateAccountInfoToRedis(const std::string& strAccount, const NFGUID& id) = 0;
    virtual bool LoadAccountInfoFromRedis(const std::string& strAccount, NFGUID& id) = 0;
    virtual void RecvAsynGetAccountInfoFromMysql(const std::vector<std::string>& fieldVec, const std::vector<std::string>& valueVec, std::string& account, NFGUID& roleId) = 0;
};

#endif